#include "pch.h"
#include "Paddle.h"
#include "GameObjects\Sphere.h"
#include "GameEngine.h"
#include "GameConstants.h"

using namespace Platform;
using namespace Windows::Foundation;

Paddle::Paddle() : Sphere()
{
	m_power = 0.0f;
	// This scale doubles, so it is actually the radius. 
	// Don't *.5 for radius, just use it as is.
	m_scale = XMFLOAT3(2.0f, 2.0f, 0.2f); 
}

void Paddle::Update(GameEngine^ engine) 
{
	XMFLOAT3 oldPosition = m_position;

	//m_position.x = (m_scale.x*.5f) + m_normalizedPosition.x * (GameConstants::MaxBound.x - m_scale.x);
	//m_position.y = (GameConstants::MaxBound.y - (m_scale.y*.5f)) - m_normalizedPosition.y * (GameConstants::MaxBound.y - m_scale.y);


	// At our current settings, the Paddle needs to move from 2.0 to 17.0 on the X
	// and 2.0 to 8.0 on the Y.
	// Therefore, X would be:   2.0 + normalizedX * ( 19.0 - (2.0*2.0));
	// And Y would be:			2.0 + normalizedY * ( 10.0 - (2.0*2.0));	
	// or Y Inverted:			(10.0 - 2.0) - normalizedY*(10.0 - (2.0*2.0));
	m_position.x = m_scale.x + m_normalizedPosition.x * ( GameConstants::MaxBound.x - m_scale.x*2.0f);
	m_position.y = (GameConstants::MaxBound.y - m_scale.y) - m_normalizedPosition.y*(GameConstants::MaxBound.y - (m_scale.y*2.0f));


	float dx = oldPosition.x - m_position.x;
	float dy = oldPosition.y - m_position.y;

	// we could be more accurate by taking the sqrt and reducing longer, but 
	// that would allow the player to "build up" power by simply wagging the paddle.
	// in this way, we reward positionnig and quick velocity jumps by trying to add polish.
	// let's test both ways during game play, but we'll start with the "polish" reward versus the "powering up" reward.
	m_power += dx*dx + dy*dy;
	m_power *= .9f;

	GameObject::Update(engine);
}